package org.ohuyo.libra.admin.dao.impl;

import java.math.BigInteger;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.ohuyo.commons.org.hibernate.criterion.DetachedCriteriaEx;
import org.ohuyo.commons.org.hibernate.criterion.Page;
import org.ohuyo.commons.org.springframework.orm.hibernate3.support.HibernateDaoSupportEx;
import org.ohuyo.libra.admin.dao.AdminDao;
import org.ohuyo.libra.server.model.table.ActionRecord;
import org.ohuyo.libra.server.model.table.AppTicketRecord;
import org.springframework.stereotype.Service;

/**
 * 
 * @author rabbit
 * 
 */
@Service("libra.admin.adminDao")
public class AdminDaoImpl extends HibernateDaoSupportEx implements AdminDao {
	@Resource(name = "libra.admin.sessionFactory")
	public void setSessionFactoryEx(SessionFactory sessionFactory) {
		// TODO Auto-generated method stub
		super.setSessionFactoryEx(sessionFactory);
	}

	public BigInteger countAppTicket() {
		return this.getHibernateTemplateEx().countBySql(
				"select * from t_app_ticket");
	}

	public BigInteger countJumpTicket() {
		return this.getHibernateTemplateEx().countBySql(
				"select * from t_jump_ticket");
	}

	public BigInteger countLoginTicket() {
		return this.getHibernateTemplateEx().countBySql(
				"select * from t_login_ticket");
	}

	@SuppressWarnings("unchecked")
	public List<AppTicketRecord> listAppTicket() {
		return this.getHibernateTemplate().findByExample(new AppTicketRecord());
	}

	/**
	 * 
	 */
	@SuppressWarnings("unchecked")
	public List<ActionRecord> listAction() {
		return this.getHibernateTemplate().findByExample(new ActionRecord());
	}

	@SuppressWarnings("unchecked")
	public List<ActionRecord> listAction(DetachedCriteriaEx criteriaEx,
			Page page) {
		return (List<ActionRecord>) this.getHibernateTemplateEx()
				.findByCriteriaEx(criteriaEx, page);
	}
}
